import { createSlice } from "@reduxjs/toolkit";

const counterSlice = createSlice({
    //配置name是方便使用dev工具式进行观察
    name: "counter",
    //配置初始化数据
    initialState: {
        counter:10,
    },
    //配置reduces,这个里面的数据是在切片的actions里面的
    reducers: {
        addNum: (state,action)=>
        {
            console.log(state,action);
            state.counter += action.payload;
        },
        subNum: (state, action) => {
            state.counter -= action.payload;
        }
    },
})

export const { addNum, subNum } = counterSlice.actions;
//导出reducer给store进行配置
export default counterSlice.reducer;

